package net.cyue.web.easyquery.provider.db.ds;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import net.cyue.web.easyquery.core.provider.api.IInstanceProvider;
import net.cyue.web.easyquery.provider.db.DBConfiguration;

public class HikariCPDataSourceProvider implements IInstanceProvider<HikariDataSource> {

    private final HikariDataSource dataSource;

    public HikariCPDataSourceProvider(DBConfiguration configuration) {
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName(configuration.getDriverName());
        hikariConfig.setJdbcUrl(configuration.getUrl());
        hikariConfig.setUsername(configuration.getUsername());
        hikariConfig.setPassword(configuration.getPassword());
        this.dataSource = new HikariDataSource(hikariConfig);
    }

    @Override
    public HikariDataSource getInstance() {
        return this.dataSource;
    }
}
